package com.atguigu.gulimall.search.config;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.elasticsearch.client.*;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class GulimallElasticSearchConfig {

    //为请求添加配置
    public static final RequestOptions COMMON_OPTIONS;

    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//            builder.addHeader("Authorization","Bearer "+TOKEN);
//            builder.setHttpAsyncResponseConsumerFactory(
//                    new HttpAsyncResponseConsumerFactory
//                            .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }


    //此处配置es
    //将RestHighLevelClient方法纳入Spring的管理
    @Bean
    public RestHighLevelClient esRestClient(){

        RestClientBuilder builder = null;

        //builder接收一个 es客户端， 使用HttpHost发送客户端请求
        builder = RestClient.builder(new HttpHost("192.168.56.10", 9200, "http"));

        //通过builder建立RestHighLevelClient
        RestHighLevelClient client = new RestHighLevelClient(builder);

        return  client;
    }
}
